#ifndef STAT_ANALYZE_H
#define STAT_ANALYZE_H


#include <stdio.h>
#include <vector>
#include <string>
#include "node.h"
#include "ast.h"
#include "symtab.h"
#include "lex.yy.h"

using namespace std;

#define STAT_ERROR        -1  // ERROR_STATE

#define GOTO(X) c_status=X;
#define L(X)	if (c_status==X) {
#define L_END	GOTO(STAT_ERROR) }

#define PUSH(X) _stack[_stackpointer++]=X;
#define POP()   _stack[--_stackpointer];
#define TOP()   _stack[_stackpointer-1];

#define N_PUSH() _node_stack[_node_stack_pointer++]=c_node;_status_stack[_status_stack_pointer++]=c_status;
#define N_POP() c_status=_status_stack[--_status_stack_pointer];c_node=_node_stack[--_node_stack_pointer];

#define LPOINT(X) Node *_tn=Node::createNode();_tn=c_node;while (_tn->rightpointer!=0) _tn=_tn->rightpointer;X=_tn;

class Stat_Analyze {
public :
	AST* ast;
	Symtab* symtab;
	Stat_Analyze();
	
	int gettoken(int t_type,char* t_name);

private :
	Node* c_node;
	int c_status;        // current status..
	
	int* _stack;
	int _stackpointer;
	
	Node** _node_stack;
	int _node_stack_pointer;

	int* _status_stack;
	int _status_stack_pointer;

	int c_depth;
	int auto_scope;
};

#endif // STAT_ANALYZE_H